




/*
'===============================================================================
'  HNG.Portal.BL.TblThanhVienRoleManagerBase
'===============================================================================
*/

using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using HNG.Portal.BLL;
using HNG.Portal.DAL;
using HNG.Portal.DAL.EntityClasses;
using HNG.Portal.DAL.FactoryClasses;
using HNG.Portal.DAL.HelperClasses;
using SD.LLBLGen.Pro.ORMSupportClasses;
using System.Windows.Forms;
namespace HNG.Portal.BLL
{
	public class TblThanhVienRoleManagerBase
	{
	    
		#region ColumnNames
		
				public const String Field_Id="Id";
				
				public const String Field_SiteMapId="SiteMapId";
				
				public const String Field_ThanhVienId="ThanhVienId";
				
				public const String Field_RoleId="RoleId";
				
		#endregion	
		/// <summary>
		/// Purpose: Class constructor.
		/// </summary>
		public TblThanhVienRoleManagerBase()
		{
			// Nothing for now.
		}
		public DataTable Clone()
		{
			DataTable dt = new DataTable();
						
			
			dt.Columns.Add(Field_Id,typeof(int));
			
						
			
			dt.Columns.Add(Field_SiteMapId,typeof(int));
			
						
			
			dt.Columns.Add(Field_ThanhVienId,typeof(int));
			
						
			
			dt.Columns.Add(Field_RoleId,typeof(int));
			
			            
            return dt;			
		}
			
		public TblThanhVienRoleEntity Convert_Entity(TblThanhVienRoleEntity _TblThanhVienRoleEntity,TblThanhVienRoleEntity _TblThanhVienRoleEntity_XML)
		{	
			
				
			_TblThanhVienRoleEntity.Id= _TblThanhVienRoleEntity_XML.Id;
				
			_TblThanhVienRoleEntity.SiteMapId= _TblThanhVienRoleEntity_XML.SiteMapId;
				
			_TblThanhVienRoleEntity.ThanhVienId= _TblThanhVienRoleEntity_XML.ThanhVienId;
				
			_TblThanhVienRoleEntity.RoleId= _TblThanhVienRoleEntity_XML.RoleId;
				
			
			return _TblThanhVienRoleEntity;
		}	
		
			
		public void InsertCollection(EntityCollection _Collection)
		{
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
            {
                adapter.SaveEntityCollection(_Collection);
            }
		}

		public TblThanhVienRoleEntity Insert(TblThanhVienRoleEntity TblThanhVienRoleEntity)
		{
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.SaveEntity(TblThanhVienRoleEntity, true);
			}
			return TblThanhVienRoleEntity;
		}

		
		public TblThanhVienRoleEntity Insert(int Id, int SiteMapId, int ThanhVienId, int RoleId)
		{
			TblThanhVienRoleEntity _TblThanhVienRoleEntity = new TblThanhVienRoleEntity();
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				
				_TblThanhVienRoleEntity.Id = Id;
				_TblThanhVienRoleEntity.SiteMapId = SiteMapId;
				_TblThanhVienRoleEntity.ThanhVienId = ThanhVienId;
				_TblThanhVienRoleEntity.RoleId = RoleId;
				adapter.SaveEntity(_TblThanhVienRoleEntity, true);
			}
			return _TblThanhVienRoleEntity;
		}

		public TblThanhVienRoleEntity Insert(int SiteMapId, int ThanhVienId, int RoleId)
		{
			TblThanhVienRoleEntity _TblThanhVienRoleEntity = new TblThanhVienRoleEntity();
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				
				_TblThanhVienRoleEntity.SiteMapId = SiteMapId;
				_TblThanhVienRoleEntity.ThanhVienId = ThanhVienId;
				_TblThanhVienRoleEntity.RoleId = RoleId;
				adapter.SaveEntity(_TblThanhVienRoleEntity, true);
			}
			return _TblThanhVienRoleEntity;
		}

		public bool Update(TblThanhVienRoleEntity _TblThanhVienRoleEntity)
		{
			bool toReturn = false;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				RelationPredicateBucket filter = new RelationPredicateBucket();
				IPredicateExpression _PredicateExpression = new PredicateExpression();
				_PredicateExpression.Add(TblThanhVienRoleFields.Id == _TblThanhVienRoleEntity.Id);
					
				filter.PredicateExpression.Add(_PredicateExpression);

				adapter.UpdateEntitiesDirectly(_TblThanhVienRoleEntity, filter);
				toReturn = true;
			}
			return toReturn;
		}
		
		public bool Update(TblThanhVienRoleEntity _TblThanhVienRoleEntity, RelationPredicateBucket filter)
		{
			bool toReturn = false;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.UpdateEntitiesDirectly(_TblThanhVienRoleEntity, filter);
				toReturn = true;
			}
			return toReturn;
		}

		public bool Update(int Id, int SiteMapId, int ThanhVienId, int RoleId)
		{
			bool toReturn = false;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				TblThanhVienRoleEntity _TblThanhVienRoleEntity = new TblThanhVienRoleEntity(Id);
				if (adapter.FetchEntity(_TblThanhVienRoleEntity))
				{
				
					_TblThanhVienRoleEntity.SiteMapId = SiteMapId;
					_TblThanhVienRoleEntity.ThanhVienId = ThanhVienId;
					_TblThanhVienRoleEntity.RoleId = RoleId;
					adapter.SaveEntity(_TblThanhVienRoleEntity, true);
					toReturn = true;
				}
			}
			return toReturn;
		}

		public bool Delete(int Id)
		{
			bool toReturn = false;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				TblThanhVienRoleEntity _TblThanhVienRoleEntity = new TblThanhVienRoleEntity(Id);
				if (adapter.FetchEntity(_TblThanhVienRoleEntity))
				{
					adapter.DeleteEntity(_TblThanhVienRoleEntity);
					toReturn = true;
				}
			}
			return toReturn;
		}
		
		public void DeleteAll() 
		{
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.DeleteEntitiesDirectly("TblThanhVienRoleEntity", null);
			}
		}
		
		
		public int DeleteById(int Id)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblThanhVienRoleFields.Id == Id);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("TblThanhVienRoleEntity", filter);
			}
			return toReturn;
		}
		
		public int DeleteBySiteMapId(int SiteMapId)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblThanhVienRoleFields.SiteMapId == SiteMapId);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("TblThanhVienRoleEntity", filter);
			}
			return toReturn;
		}
		
		public int DeleteByThanhVienId(int ThanhVienId)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblThanhVienRoleFields.ThanhVienId == ThanhVienId);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("TblThanhVienRoleEntity", filter);
			}
			return toReturn;
		}
		
		public int DeleteByRoleId(int RoleId)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblThanhVienRoleFields.RoleId == RoleId);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("TblThanhVienRoleEntity", filter);
			}
			return toReturn;
		}
		

		
		public TblThanhVienRoleEntity SelectOne(int Id)
		{
			TblThanhVienRoleEntity toReturn = null;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				TblThanhVienRoleEntity _TblThanhVienRoleEntity = new TblThanhVienRoleEntity(Id);
				if (adapter.FetchEntity(_TblThanhVienRoleEntity))
				{
					toReturn = _TblThanhVienRoleEntity;
				}
			}
			return toReturn;
		}

		// Return EntityCollection
		public EntityCollection SelectAll()
		{
			EntityCollection _TblThanhVienRoleCollection = new EntityCollection( new TblThanhVienRoleEntityFactory());
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_TblThanhVienRoleCollection, null, 0, null);
			}
			return _TblThanhVienRoleCollection;
		}
		
		// Return DataTable
		public DataTable SelectAllRDT()
		{
			DataTable toReturn = new DataTable();
			EntityCollection _TblThanhVienRoleCollection = new EntityCollection(new TblThanhVienRoleEntityFactory());
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_TblThanhVienRoleCollection.EntityFactoryToUse.CreateFields(), toReturn, null, true);
			}
			return toReturn;
		}

		
		// Return EntityCollection
		public EntityCollection SelectById(int Id)
		{
			EntityCollection _TblThanhVienRoleCollection = new EntityCollection(new TblThanhVienRoleEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblThanhVienRoleFields.Id == Id);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_TblThanhVienRoleCollection, filter, 0, null);
			}
			return _TblThanhVienRoleCollection;
		}
		
		// Return DataTable
		public DataTable SelectByIdRDT(int Id)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _TblThanhVienRoleCollection = new EntityCollection(new TblThanhVienRoleEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblThanhVienRoleFields.Id == Id);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_TblThanhVienRoleCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		// Return EntityCollection
		public EntityCollection SelectBySiteMapId(int SiteMapId)
		{
			EntityCollection _TblThanhVienRoleCollection = new EntityCollection(new TblThanhVienRoleEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblThanhVienRoleFields.SiteMapId == SiteMapId);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_TblThanhVienRoleCollection, filter, 0, null);
			}
			return _TblThanhVienRoleCollection;
		}
		
		// Return DataTable
		public DataTable SelectBySiteMapIdRDT(int SiteMapId)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _TblThanhVienRoleCollection = new EntityCollection(new TblThanhVienRoleEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblThanhVienRoleFields.SiteMapId == SiteMapId);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_TblThanhVienRoleCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		// Return EntityCollection
		public EntityCollection SelectByThanhVienId(int ThanhVienId)
		{
			EntityCollection _TblThanhVienRoleCollection = new EntityCollection(new TblThanhVienRoleEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblThanhVienRoleFields.ThanhVienId == ThanhVienId);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_TblThanhVienRoleCollection, filter, 0, null);
			}
			return _TblThanhVienRoleCollection;
		}
		
		// Return DataTable
		public DataTable SelectByThanhVienIdRDT(int ThanhVienId)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _TblThanhVienRoleCollection = new EntityCollection(new TblThanhVienRoleEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblThanhVienRoleFields.ThanhVienId == ThanhVienId);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_TblThanhVienRoleCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		// Return EntityCollection
		public EntityCollection SelectByRoleId(int RoleId)
		{
			EntityCollection _TblThanhVienRoleCollection = new EntityCollection(new TblThanhVienRoleEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblThanhVienRoleFields.RoleId == RoleId);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_TblThanhVienRoleCollection, filter, 0, null);
			}
			return _TblThanhVienRoleCollection;
		}
		
		// Return DataTable
		public DataTable SelectByRoleIdRDT(int RoleId)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _TblThanhVienRoleCollection = new EntityCollection(new TblThanhVienRoleEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblThanhVienRoleFields.RoleId == RoleId);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_TblThanhVienRoleCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		

	}
}
